\chapter{命令参考}
\label{app:commands}

本附录汇总 cpp-orchestrator 提供的 Python API、命令行工具与常用编译命令。

\section{Python API}

\subsection{TypeMapper 类}

\begin{lstlisting}[language=Python]
from orchestrator.mapping.type_mapper import TypeMapper

mapper = TypeMapper()
\end{lstlisting}

\textbf{常用方法：}

\begin{description}
    \item[\code{map\_type(csharp\_type: str) -> TypeMapping}] 将 C\# 类型映射为 C++ 类型
    \begin{lstlisting}[language=Python]
result = mapper.map_type("List<string>")
# result.cpp_type -> "std::vector<std::string>"
# result.includes -> ["<vector>", "<string>"]
    \end{lstlisting}

    \item[\code{add\_custom\_mapping(csharp\_type, cpp\_type, includes)}] 注册自定义映射
    \begin{lstlisting}[language=Python]
mapper.add_custom_mapping(
    "Vector3", "glm::vec3", ["glm/glm.hpp"]
)
    \end{lstlisting}
\end{description}

\subsection{SymbolResolver 类}

\begin{lstlisting}[language=Python]
from orchestrator.mapping.symbol_resolver import SymbolResolver

resolver = SymbolResolver()
resolver.setup_default_mappings()
\end{lstlisting}

\textbf{常用方法：}

\begin{description}
    \item[\code{resolve\_namespace(csharp\_ns: str) -> str}] 将 C\# 命名空间转换为 C++ 形式
    \begin{lstlisting}[language=Python]
resolver.resolve_namespace("MyApp.Services")
# "my_app::services"
    \end{lstlisting}

    \item[\code{add\_namespace\_mapping(csharp, cpp)}] 添加自定义命名空间映射
\end{description}

\subsection{CppEmitter 类}

\begin{lstlisting}[language=Python]
from orchestrator.codegen.emitter import CppEmitter

emitter = CppEmitter(type_mapper, symbol_resolver)
\end{lstlisting}

\textbf{常用方法：}

\begin{description}
    \item[\code{emit\_class(class\_ir, output\_dir) -> (Path, Path)}] 生成头文件与源文件
\end{description}

\subsection{IR 构建与归一化}

\begin{description}
    \item[\code{build\_ir\_from\_roslyn\_json(json\_str)}] 从 Roslyn JSON 中解析类定义
    \item[\code{normalize\_ir(class\_decl)}] 将属性展开为 getter/setter 等标准结构
\end{description}

\subsection{命名辅助函数}

\begin{lstlisting}[language=Python]
from orchestrator.codegen.naming import (
    to_snake_case,
    to_class_name,
    to_field_name,
    to_method_name,
)
\end{lstlisting}

\begin{description}
    \item[\texttt{to\_snake\_case}] 示例：\texttt{to\_snake\_case("GetUserByID")} 返回 \texttt{get\_user\_by\_id}
    \item[\texttt{to\_field\_name}] 示例：\texttt{to\_field\_name("userId")} 返回 \texttt{m\_user\_id}
\end{description}

\section{命令行编译参考}

\subsection{g++}

\begin{description}
    \item[基础编译]
    \begin{lstlisting}[style=bash]
g++ -std=c++20 -c source.cpp -I include -o source.o
    \end{lstlisting}

    \item[开启警告]
    \begin{lstlisting}[style=bash]
g++ -std=c++20 -Wall -Wextra -Wpedantic -c source.cpp -I include
    \end{lstlisting}

    \item[优化级别]
    \begin{lstlisting}[style=bash]
g++ -std=c++20 -O2 -c source.cpp -I include
    \end{lstlisting}
\end{description}

\subsection{clang++}

\begin{lstlisting}[style=bash]
clang++ -std=c++20 -stdlib=libc++ \
    -Wall -Wextra -c source.cpp -I include
\end{lstlisting}

\subsection{MSVC}

\begin{lstlisting}[style=bash]
cl /std:c++20 /W4 /EHsc /I include source.cpp
\end{lstlisting}

\subsection{CMake 最小示例}

\begin{lstlisting}[language=C++]
cmake_minimum_required(VERSION 3.21)
project(MyProject LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
add_library(my_project STATIC
    src/foo.cpp
    src/bar.cpp
)
target_include_directories(my_project PUBLIC include)
\end{lstlisting}

以上命令可直接用于测试生成代码是否正确编译。
